package com.jt.demo01;
/**JDK动态代理*/
import com.jt.demo01.config.SpringConfig;
import com.jt.demo01.proxy.JDKProxy;
import com.jt.demo01.service.UserService;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;

public class SpringTx {
    public static void main(String[] args) {
        ApplicationContext context = new AnnotationConfigApplicationContext(SpringConfig.class);
        UserService userService = context.getBean(UserService.class);//获取本来的对象
        userService.addUser();
        userService.deleteUser();
        System.out.println(userService.getClass());

        //获取代理对象
        UserService proxy = (UserService) JDKProxy.getProxy(userService);//通过普通对象获取代理对象
        System.out.println(proxy.getClass());

        //基于代理对象,执行业务操作 实现方法扩展
        proxy.addUser();
        proxy.deleteUser();
    }
}
